/**
 ***************************************(C) COPYRIGHT 2018 DJI***************************************
 * @file       bsp_uart.h
 * @brief      this file contains the common defines and functions prototypes for 
 *             the bsp_uart.c driver
 * @note         
 * @Version    V1.0.0
 * @Date       Jan-30-2018      
 ***************************************(C) COPYRIGHT 2018 DJI***************************************
 */

#ifndef __BSP_UART_H__
#define __BSP_UART_H__

#include "usart.h"
#include "Information_Task.h"
#include "my_main.h"




#define UART_RX_DMA_SIZE (1024)

#define DBUS_MAX_LEN     (50)
#define DBUS_BUFLEN      (18)
#define DBUS_HUART       huart3 /* for dji remote controler reciever */



#define REFERENCE_HUART       huart6 /* for dji remote controler reciever */




#define RC_CH_VALUE_MIN         ((uint16_t)364)
#define RC_CH_VALUE_OFFSET      ((uint16_t)1024)
#define RC_CH_VALUE_MAX         ((uint16_t)1684)
/* ----------------------- RC Switch Definition----------------------------- */
#define RC_SW_UP                ((uint16_t)1)
#define RC_SW_MID               ((uint16_t)3)
#define RC_SW_DOWN              ((uint16_t)2)
#define switch_is_down(s)       (s == RC_SW_DOWN)
#define switch_is_mid(s)        (s == RC_SW_MID)
#define switch_is_up(s)         (s == RC_SW_UP)
#define REMOTE_SWITCH_VALUE_UP         	RC_SW_UP
#define REMOTE_SWITCH_VALUE_DOWN				RC_SW_DOWN
#define REMOTE_SWITCH_VALUE_CENTRAL			RC_SW_MID



typedef enum
{
	null_uart_e,
	DBUS_uart_e=(0x01 << 0),
	
	All_uart_e=null_uart_e|DBUS_uart_e
}bsp_uart_e;

typedef struct
{
	u8 buff[DBUS_BUFLEN];
	uint16_t lens;
	u8 pre;
}DBUS_Uart_Rx_buff_t;
extern DBUS_Uart_Rx_buff_t   DBUS_BUF[2];



void uart_receive_handler(UART_HandleTypeDef *huart);
void Change_DMA_Buff(DMA_Stream_TypeDef* DMAy_Streamx);
uint32_t DMA_GetCurrentMemoryTarget(DMA_Stream_TypeDef* DMAy_Streamx);
int uart_receive_dma_no_it(UART_HandleTypeDef* huart, uint8_t* pData, uint32_t Size);
void Double_DMA_RX0_IDE(DMA_HandleTypeDef *hdma);
void Double_DMA_RX1_IDE(DMA_HandleTypeDef *hdma);
void Double_DMA_ERROR_IDE(DMA_HandleTypeDef *hdma);
void usart6_tx_dma_enable(uint8_t *data, uint16_t len);
void usart6_init(uint8_t *rx1_buf, uint8_t *rx2_buf, uint16_t dma_buf_num);
#endif

